# list
a = []
#末尾追加
a.append(1)
print(a)

#两个序列的拼接
a += ["b"]
print(a)

# 指定位置插入
l = [1, 2, 3, 4, 5]
l.insert(3, 10)
print(l)


# 按索引取值
print(a[1])


# 切片
print(l[1:4])


# 列表最后一个
print(l[-1])


# 间隔取值
l_2 = list(range(100))
print(l_2[0:20:3])


# 检索
l_3 = ["a", "b", "c", "d", "t"]
print(l_3.index("b"))


# 索引赋值
l_3[4] = "o"
print(l_3)


# 切片赋值
l_3[0:3] = "1"
print(l_3)


# 删除末尾元素并返回
l_3.pop()
print(l_3)


# 清除列表的元素，不会改变内存地址
l_3.clear()
print(l_3)


# 排序1
l_4 = [13, 1, 4, 2, 9]
l_4.sort()
print(l_4)

# 排序2
l_5 = [13, 1, 4, 2, 9]
l_6 = l_5.sorted()
print(l_5)
print(l_6)

# 倒序
l_6.reverse()
print(l_6)




# tuple
# 索引取值
t = (4, 2, "a", "d", 5)
print(t[2])


# index
print(t.index(0))


# 切片
print(t[0:3])




# dict
# 键対值赋值
d = {"a":3,"b":4,"c":2,"o":5}
d["t"] = 6
print(d)


# 合并字典
d_1 = {"h": 11}
d.update(d_1)
print(d)


# setdefault,没有key则加入新元素
d.setdefault("k", 13)
print(d)

# setdefault,有key则返回key值
print(d.setdefault("a", 0))
print(d)


# 键对值访问
print(d["c"])

print(d.get("b"))


# 返回所有key
print(d.keys())


# 返回所有value
print(d.values())


# 返回所有键对值
print(d.items())


# 键对值赋值
d["a"] = 55
print(d)

#update
d.update({"b": 200, "c": 300})
print(d)


# 删除当前键对值
d.pop("k")
print(d)

# 返回一个item
print(d.popitem())


# 清空字典
d.clear()
print(d)




# set
s = set()
# 添加
s.add("a")
print(s)


# 判断
print("a" in s)


# union合并
s_1 = {"b", "c"}
s_2 = s.union(s_1)
print(s_2)


# 移除
s_2.remove("a")
print(s_2)

s_2.discard("t")
print(s_2)


# 无序删除并返回
s_2.pop()
print(s_2)

